﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Modulos/ModuloVenta/VistaControl/MasterPageVenta.master" AutoEventWireup="true" CodeFile="RegistroVenta.aspx.cs" Inherits="Modulos_ModuloVenta_VistaControl_Default" %>

<%@ Register assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.DynamicData" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

   
    
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
        SelectCommand="SELECT * FROM [DETALLE_VENTA]" 
        ConflictDetection="CompareAllValues" 
        DeleteCommand="DELETE FROM [DETALLE_VENTA] WHERE [DT_VNT_COD] = @original_DT_VNT_COD AND [PRD_VNT_COD] = @original_PRD_VNT_COD AND [VNT_COD] = @original_VNT_COD AND [DT_VNT_CANT] = @original_DT_VNT_CANT AND [DT_VNT_STOTAL] = @original_DT_VNT_STOTAL" 
        InsertCommand="INSERT INTO [DETALLE_VENTA] ([PRD_VNT_COD], [VNT_COD], [DT_VNT_CANT], [DT_VNT_STOTAL]) VALUES (@PRD_VNT_COD, @VNT_COD, @DT_VNT_CANT, @DT_VNT_STOTAL);

UPDATE [PRODUCTO_VENTA] SET [PRD_VNT_STOCK] = [PRD_VNT_STOCK] - @DT_VNT_CANT WHERE (([PRD_VNT_COD] = @PRD_VNT_COD));

SELECT @PRECIO=[PRD_VNT_PRC] FROM [PRODUCTO_VENTA] WHERE (([PRD_VNT_COD] = @PRD_VNT_COD));

UPDATE [VENTA] SET [VNT_TOTAL] = [VNT_TOTAL] + @DT_VNT_CANT * @PRECIO WHERE (([VNT_COD] = @VNT_COD))" 
        OldValuesParameterFormatString="original_{0}" 
        
        
        
        
        UpdateCommand="UPDATE [DETALLE_VENTA] SET [PRD_VNT_COD] = @PRD_VNT_COD, [VNT_COD] = @VNT_COD, [DT_VNT_CANT] = @DT_VNT_CANT, [DT_VNT_STOTAL] = @DT_VNT_STOTAL WHERE [DT_VNT_COD] = @original_DT_VNT_COD AND [PRD_VNT_COD] = @original_PRD_VNT_COD AND [VNT_COD] = @original_VNT_COD AND [DT_VNT_CANT] = @original_DT_VNT_CANT AND [DT_VNT_STOTAL] = @original_DT_VNT_STOTAL">
        <DeleteParameters>
            <asp:Parameter Name="original_DT_VNT_COD" Type="Decimal" />
            <asp:Parameter Name="original_PRD_VNT_COD" Type="Decimal" />
            <asp:Parameter Name="original_VNT_COD" Type="Decimal" />
            <asp:Parameter Name="original_DT_VNT_CANT" Type="Int32" />
            <asp:Parameter Name="original_DT_VNT_STOTAL" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="PRD_VNT_COD" Type="Decimal" />
            <asp:Parameter Name="VNT_COD" Type="Decimal" />
            <asp:Parameter Name="DT_VNT_CANT" Type="Int32" />
            <asp:Parameter Name="DT_VNT_STOTAL" Type="Int32" />
            <asp:Parameter Name="original_DT_VNT_COD" Type="Decimal" />
            <asp:Parameter Name="original_PRD_VNT_COD" Type="Decimal" />
            <asp:Parameter Name="original_VNT_COD" Type="Decimal" />
            <asp:Parameter Name="original_DT_VNT_CANT" Type="Int32" />
            <asp:Parameter Name="original_DT_VNT_STOTAL" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="PRD_VNT_COD" Type="Decimal" />
            <asp:Parameter Name="VNT_COD" Type="Decimal" />
            <asp:Parameter Name="DT_VNT_CANT" Type="Int32" />
            <asp:Parameter Name="DT_VNT_STOTAL" />
            <asp:Parameter Name="PRECIO" />
        </InsertParameters>
    </asp:SqlDataSource>

   
    
    <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
        SelectCommand="SELECT * FROM [VENTA]">
    </asp:SqlDataSource>

   
    
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>"
        SelectCommand="SELECT * FROM [VENTA]" ConflictDetection="CompareAllValues" 
        DeleteCommand="DELETE FROM [VENTA] WHERE [VNT_COD] = @original_VNT_COD AND [USR_RUT] = @original_USR_RUT AND [VNT_DATE] = @original_VNT_DATE AND [VNT_TOTAL] = @original_VNT_TOTAL AND [VNT_VLC] = @original_VNT_VLC" 
        InsertCommand="INSERT INTO [VENTA] ([USR_RUT], [VNT_DATE], [VNT_TOTAL], [VNT_VLC]) VALUES (@USR_RUT, @VNT_DATE, '0', @VNT_VLC)" 
        OldValuesParameterFormatString="original_{0}" 
        
        
        UpdateCommand="UPDATE [VENTA] SET [USR_RUT] = @USR_RUT, [VNT_DATE] = @VNT_DATE, [VNT_TOTAL] = @VNT_TOTAL, [VNT_VLC] = @VNT_VLC WHERE [VNT_COD] = @original_VNT_COD AND [USR_RUT] = @original_USR_RUT AND [VNT_DATE] = @original_VNT_DATE AND [VNT_TOTAL] = @original_VNT_TOTAL AND [VNT_VLC] = @original_VNT_VLC">
        <DeleteParameters>
            <asp:Parameter Name="original_VNT_COD" Type="Decimal" />
            <asp:Parameter Name="original_USR_RUT" Type="Int32" />
            <asp:Parameter Name="original_VNT_DATE" Type="DateTime" />
            <asp:Parameter Name="original_VNT_TOTAL" Type="Int32" />
            <asp:Parameter Name="original_VNT_VLC" Type="Boolean" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="USR_RUT" Type="Int32" />
            <asp:Parameter Name="VNT_DATE" Type="DateTime" />
            <asp:Parameter Name="VNT_TOTAL" Type="Int32" />
            <asp:Parameter Name="VNT_VLC" Type="Boolean" />
            <asp:Parameter Name="original_VNT_COD" Type="Decimal" />
            <asp:Parameter Name="original_USR_RUT" Type="Int32" />
            <asp:Parameter Name="original_VNT_DATE" Type="DateTime" />
            <asp:Parameter Name="original_VNT_TOTAL" Type="Int32" />
            <asp:Parameter Name="original_VNT_VLC" Type="Boolean" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="USR_RUT" Type="Int32" />
            <asp:Parameter Name="VNT_DATE" Type="DateTime" />
            <asp:Parameter Name="VNT_VLC" Type="Boolean" />
        </InsertParameters>
    </asp:SqlDataSource>

   
    
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
        
        SelectCommand="SELECT * FROM [PRODUCTO_VENTA]">
    </asp:SqlDataSource>
    
    <h2> Registro de Ventas </h2>
    <p>Aquí podrá registrar las ventas que se realicen en CEII 
    </p>
    
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="VNT_COD" 
        DataSourceID="SqlDataSource2" ondatabinding="Page_Load">
        <Columns>
            <asp:CommandField ShowEditButton="True" />
            <asp:BoundField DataField="VNT_COD" HeaderText="Código Venta" InsertVisible="False" 
                ReadOnly="True" SortExpression="VNT_COD" />
            <asp:BoundField DataField="USR_RUT" HeaderText="Rut Usuario" 
                SortExpression="USR_RUT" />
            <asp:BoundField DataField="VNT_DATE" HeaderText="Fecha" 
                SortExpression="VNT_DATE" />
            <asp:BoundField DataField="VNT_TOTAL" HeaderText="Total" 
                SortExpression="VNT_TOTAL" />
            <asp:CheckBoxField DataField="VNT_VLC" HeaderText="Validación" 
                SortExpression="VNT_VLC" />
        </Columns>
    </asp:GridView>
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="VNT_COD" 
        DataSourceID="SqlDataSource2">
        <EditItemTemplate>
            VNT_COD:
            <asp:Label ID="VNT_CODLabel1" runat="server" Text='<%# Eval("VNT_COD") %>' />
            <br />
            USR_RUT:
            <asp:TextBox ID="USR_RUTTextBox" runat="server" Text='<%# Bind("USR_RUT") %>' />
            <br />
            VNT_DATE:
            <asp:TextBox ID="VNT_DATETextBox" runat="server" 
                Text='<%# Bind("VNT_DATE") %>' />
            <br />
            VNT_TOTAL:
            <asp:TextBox ID="VNT_TOTALTextBox" runat="server" 
                Text='<%# Bind("VNT_TOTAL") %>' />
            <br />
            VNT_VLC:
            <asp:CheckBox ID="VNT_VLCCheckBox" runat="server" 
                Checked='<%# Bind("VNT_VLC") %>' />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                CommandName="Update" Text="Actualizar" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
        </EditItemTemplate>
        <InsertItemTemplate>
            &nbsp;<table style="width: 100%">
                <tr>
                    <td style="width: 62px">
                        Rut Usuario</td>
                    <td style="width: 2px">
                        :</td>
                    <td>
                        <asp:DropDownList ID="DropDownList1" runat="server" 
                            DataSourceID="SqlDataSource2" DataTextField="USR_RUT" DataValueField="USR_RUT" 
                            SelectedValue='<%# Bind("USR_RUT") %>'>
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AppCeiiConnectionString %>" 
        OldValuesParameterFormatString="original_{0}" 
                            SelectCommand="SELECT * FROM [USUARIO]" 
                            DeleteCommand="DELETE FROM [USUARIO] WHERE [USR_RUT] = @original_USR_RUT" 
                            InsertCommand="INSERT INTO [USUARIO] ([USR_RUT], [NOM_USR], [AP_PAT_USR], [AP_MAT_USR], [FONO_USR], [MAIL_USR], [PASS_USR], [TIPO_USR], [ESTADO_USR]) VALUES (@USR_RUT, @NOM_USR, @AP_PAT_USR, @AP_MAT_USR, @FONO_USR, @MAIL_USR, @PASS_USR, @TIPO_USR, @ESTADO_USR)" 
                            
                            UpdateCommand="UPDATE [USUARIO] SET [NOM_USR] = @NOM_USR, [AP_PAT_USR] = @AP_PAT_USR, [AP_MAT_USR] = @AP_MAT_USR, [FONO_USR] = @FONO_USR, [MAIL_USR] = @MAIL_USR, [PASS_USR] = @PASS_USR, [TIPO_USR] = @TIPO_USR, [ESTADO_USR] = @ESTADO_USR WHERE [USR_RUT] = @original_USR_RUT">
                            <DeleteParameters>
                                <asp:Parameter Name="original_USR_RUT" Type="Int32" />
                            </DeleteParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="NOM_USR" Type="String" />
                                <asp:Parameter Name="AP_PAT_USR" Type="String" />
                                <asp:Parameter Name="AP_MAT_USR" Type="String" />
                                <asp:Parameter Name="FONO_USR" Type="String" />
                                <asp:Parameter Name="MAIL_USR" Type="String" />
                                <asp:Parameter Name="PASS_USR" Type="String" />
                                <asp:Parameter Name="TIPO_USR" Type="String" />
                                <asp:Parameter Name="ESTADO_USR" Type="Boolean" />
                                <asp:Parameter Name="original_USR_RUT" Type="Int32" />
                            </UpdateParameters>
                            <InsertParameters>
                                <asp:Parameter Name="USR_RUT" Type="Int32" />
                                <asp:Parameter Name="NOM_USR" Type="String" />
                                <asp:Parameter Name="AP_PAT_USR" Type="String" />
                                <asp:Parameter Name="AP_MAT_USR" Type="String" />
                                <asp:Parameter Name="FONO_USR" Type="String" />
                                <asp:Parameter Name="MAIL_USR" Type="String" />
                                <asp:Parameter Name="PASS_USR" Type="String" />
                                <asp:Parameter Name="TIPO_USR" Type="String" />
                                <asp:Parameter Name="ESTADO_USR" Type="Boolean" />
                            </InsertParameters>
    </asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td style="width: 62px">
                        Fecha</td>
                    <td style="width: 2px">
                        :</td>
                    <td>
                        
                        <asp:TextBox ID="TextBox1" runat="server" 
                        Value='<%# System.DateTime.Now.ToString("dd-MM-yyyy") %>'
                        Text='<%# Bind("VNT_DATE", "{0:D}") %>'>
                        </asp:TextBox>
                        
                    </td>
                </tr>
                <tr>
                    <td style="width: 62px">
                        Total</td>
                    <td style="width: 2px">
                        :</td>
                    <td>
                        <asp:TextBox ID="VNT_TOTALTextBox" runat="server" 
                            Text='<%# Bind("VNT_TOTAL") %>' />
                    </td>
                </tr>
                <tr>
                    <td style="width: 62px">
                        Validación</td>
                    <td style="width: 2px">
                        :</td>
                    <td>
                        <asp:CheckBox ID="VNT_VLCCheckBox" runat="server"
                            Checked='<%# Bind("VNT_VLC") %>' />
                    </td>
                </tr>
                <tr>
                    <td style="width: 62px">
                        Detalle</td>
                    <td style="width: 2px">
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td style="width: 62px">
                        Código</td>
                    <td style="width: 2px">
                        Nombre Producto</td>
                    <td>
                        Cantidad</td>
                </tr>
                <tr>
                    <td>
                    <!--
                        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
                        
                        <headertemplate>
                                <table border="1">
                                                                    
                                </table>
                            </headertemplate>
                            <itemtemplate>
                                <tr>
                                    <td>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("PRD_VNT_COD") %>'></asp:Label>
                                        
                                    </td>
                                    <td>
                                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("PRD_VNT_NMB") %>'></asp:Label>
                                       
                                    </td>
                                    <td>
                                        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                                    </td>
                                   
                                </tr>
                            </itemtemplate>
                            <footertemplate>
                                </table>
                            </footertemplate>
                         
                        </asp:Repeater>
                        -->
                        
                        
                        <asp:FormView ID="FormView2" runat="server" DataKeyNames="DT_VNT_COD" 
                            DataSourceID="SqlDataSource3" Width="39px">
                            <EditItemTemplate>
                                DT_VNT_COD:
                                <asp:Label ID="DT_VNT_CODLabel1" runat="server" 
                                    Text='<%# Eval("DT_VNT_COD") %>' />
                                <br />
                                PRD_VNT_COD:
                                <asp:TextBox ID="PRD_VNT_CODTextBox" runat="server" 
                                    Text='<%# Bind("PRD_VNT_COD") %>' />
                                <br />
                                VNT_COD:
                                <asp:TextBox ID="VNT_CODTextBox" runat="server" Text='<%# Bind("VNT_COD") %>' />
                                <br />
                                DT_VNT_CANT:
                                <asp:TextBox ID="DT_VNT_CANTTextBox" runat="server" 
                                    Text='<%# Bind("DT_VNT_CANT") %>' />
                                <br />
                                DT_VNT_STOTAL:
                                <asp:TextBox ID="DT_VNT_STOTALTextBox" runat="server" 
                                    Text='<%# Bind("DT_VNT_STOTAL") %>' />
                                <br />
                                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                                    CommandName="Update" Text="Actualizar" />
                                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                                    CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <br />
                                <table style="width: 100%">
                                    <tr>
                                        <td style="width: 44px">
                                            Producto</td>
                                        <td style="width: 4px">
                                            :</td>
                                        <td>
                                            <asp:DropDownList ID="DropDownList2" runat="server"
                                                DataSourceID="SqlDataSource1" DataTextField="PRD_VNT_NMB" DataValueField="PRD_VNT_COD"
                                                SelectedValue='<%# Bind("PRD_VNT_COD") %>'>
                                            </asp:DropDownList>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 44px">
                                            venta&nbsp;</td>
                                        <td style="width: 4px">
                                            :</td>
                                        <td>
                                            <asp:DropDownList ID="DropDownList3" runat="server"
                                                DataSourceID="SqlDataSource4" DataTextField="VNT_COD" DataValueField="VNT_COD"
                                                SelectedValue='<%# Bind("VNT_COD") %>'>
                                            </asp:DropDownList>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 44px">
                                            cantidad</td>
                                        <td style="width: 4px">
                                            :</td>
                                        <td>
                                            <asp:TextBox ID="DT_VNT_CANTTextBox" runat="server" 
                                                Text='<%# Bind("DT_VNT_CANT") %>' />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 44px">
                                            subtotal</td>
                                        <td style="width: 4px">
                                            :</td>
                                        <td>

                                            <asp:TextBox ID="DT_VNT_STOTALTextBox" runat="server" 
                                                Text='<%# Bind("DT_VNT_STOTAL") %>' />
                                        </td>
                                    </tr>
                                </table>
                                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                                    CommandName="Insert" Text="Insertar" />
                                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                                    CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <br />
                                &nbsp;&nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                                    CommandName="New" Text="Nuevo" />
                            </ItemTemplate>
                            <EmptyDataTemplate>
                                <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                                    CommandName="New" Text="Nuevo" />
                            </EmptyDataTemplate>
                        </asp:FormView>
                    </td>
                </tr>
            </table>
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                CommandName="Insert" Text="Insertar" />
            &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
            &nbsp;
            <br />
        </InsertItemTemplate>
        <EmptyDataTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Venta" />
        </EmptyDataTemplate>
        <ItemTemplate>
            <br />
            <!--
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" 
                CommandName="Edit" Text="Editar" />
            &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" 
                CommandName="Delete" Text="Eliminar" />
            &nbsp;
            -->
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Nuevo" />
        </ItemTemplate>
    </asp:FormView>
    <asp:GridView ID="GridView2" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="DT_VNT_COD" 
        DataSourceID="SqlDataSource3">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="DT_VNT_COD" HeaderText="Código Detalle" 
                InsertVisible="False" ReadOnly="True" SortExpression="DT_VNT_COD" />
            <asp:BoundField DataField="PRD_VNT_COD" HeaderText="Código Producto" 
                SortExpression="PRD_VNT_COD" />
            <asp:BoundField DataField="VNT_COD" HeaderText="Código Venta" 
                SortExpression="VNT_COD" />
            <asp:BoundField DataField="DT_VNT_CANT" HeaderText="Cantidad Venta" 
                SortExpression="DT_VNT_CANT" />
            <asp:BoundField DataField="DT_VNT_STOTAL" HeaderText="Subtotal Venta" 
                SortExpression="DT_VNT_STOTAL" />
        </Columns>
    </asp:GridView>
    <br />  
    
</asp:Content>

